import { formControlService } from './../services/form-contorl-service';
import { FormService } from './../services/form-sevice';
import { FormBase } from './../../shared/from/form-base';
import { Globals } from './../../../shared/global';
import { Component, OnInit, Input } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
@Component({
  selector: 'ree-create-device',
  templateUrl: './create-device.component.html',
  styleUrls: ['./create-device.component.scss'],
  providers: [formControlService, FormService]
})
export class CreateDeviceComponent implements OnInit {

  formChilds: FormBase<any>[];
  profile: FormGroup;
  validateForm: FormGroup;

  constructor(
    private fb: FormBuilder,
    private Globals: Globals,
    private fcs: formControlService,
    private fs: FormService
  ) {}

  ngOnInit() {
    this.validateForm = this.fb.group({
      sid: [null, [Validators.required]],
      voltage: [null, [Validators.required]],
      power: [null, [Validators.required]],
      dateOfProduct: [null, [Validators.required]],
      model: [null, [Validators.required]],
      brand: ["公司品牌", [Validators.required]],
      deviceType: [null, [Validators.required]],
    });
  }

  getFormControl(name) {
    return this.validateForm.controls[name];
  }

  ngOnDestroy() {
    this.Globals.paths.path.pop()
  }

  selectedOption;
  searchOptions = [
    { value: '空压机', label: '空压机' },
    { value: '干燥机', label: '干燥机' },
    { value: '冷冻机', label: '冷冻机' }
  ];

  _submitForm() {
    for (const i in this.validateForm.controls) {
      this.validateForm.controls[i].markAsDirty();
    }
    console.log(this.validateForm.value)
  }


  changeType() {
    console.log(this.validateForm.value.deviceType)
    this.formChilds = this.fs.getItemOfForm();
    this.validateForm.controls.profile = this.profile = this.fcs.toFormGroup(this.formChilds);
  }

}
